package com.hncu.test;

import java.util.Scanner;

public class Demo2 {//用StringBuilder进行字符串反转

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.nextLine();
        System.out.println("反转后："+reverse(s));//传字符串
    }
    public static StringBuilder reverse(String s){
        StringBuilder sb = new StringBuilder();//创建可变空字符串对象sb
        StringBuilder sb1 = new StringBuilder(s);//创建有内容的可变字符串对象sb2
        sb1.reverse();//将字符串对象s的内容反转
//        for (int i = s.length()-1;i>=0;i--){
//            sb.append(s.charAt(i));//在可变字符串对象sb中添加反转数据
//        }
        return sb1;
        //或者return sb；
    }
}
